package cn.itcast.exam.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class jdbctemplate {
    private  static Connection connection=null;

  private static DataSource ds   =    new  ComboPooledDataSource();

    /**
     *
     * @return
     */
  public static Connection getConnection(){
      try {
          connection = ds.getConnection();
      } catch (SQLException e) {
          e.printStackTrace();
      }
return connection;


  }public static JdbcTemplate getjdbctemplate(){
      return new JdbcTemplate(ds);


    }

    /**
     *
     * @return
     */
  public static  DataSource getDateSouce(){

      return ds;

  }
    public static  void close(Connection connection, Statement stmt , ResultSet rs){
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }


    }public static void close(Connection conn, Statement stmt) {
        close(conn, stmt, null);
    }public static void main(String[] args) {
        System.out.println(getConnection());
    }

}
